﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.OleDb;

namespace Zatvor
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            String cStr = ConfigurationManager.ConnectionStrings["konekcija"].ConnectionString;
            OleDbConnection DBCon = new OleDbConnection(cStr);
            string sql = "INSERT INTO [Zatvorenici] ([ime], [prezime],[kazna]) VALUES ( @ime, @prezime,@kazna)";
            DBCon.Open();
            OleDbCommand cmd = new OleDbCommand(sql, DBCon);
            cmd.Parameters.AddWithValue("@ime", TextBoxIme.Text);
            cmd.Parameters.AddWithValue("@prezime", TextBoxPrezime.Text);
            cmd.Parameters.AddWithValue("@kazna", "3");

            string prasalnik = "SELECT * FROM Zatvorenici";

            OleDbCommand komanda = new OleDbCommand(prasalnik, DBCon);
            OleDbDataReader i = komanda.ExecuteReader();
            int pom = 0;
            while (i.Read())
            {
                if (String.Compare(TextBoxIme.Text.ToString(), i.GetValue(1).ToString()) == 0 && String.Compare(TextBoxPrezime.Text.ToString(), i.GetValue(2).ToString()) == 0)
                {
                    pom = 1;
                }
            }
            if (pom == 0)
            {
                cmd.ExecuteNonQuery();                
            }
            DBCon.Close();
        }
    }
}